package com.matrix.draft.juc.day7;

import java.util.concurrent.locks.ReentrantReadWriteLock;

/**
 * 读写锁
 */
public class TestReadWriteLock {
    private ReentrantReadWriteLock rw = new ReentrantReadWriteLock();
    private ReentrantReadWriteLock.ReadLock r = rw.readLock();
    private ReentrantReadWriteLock.WriteLock w = rw.writeLock();

    // 读操作
    private void read(){
        r.lock();
        // ...
        r.unlock();
    }

    // 写操作
    public void write(Object data){
        w.lock();
        // ...
        w.unlock();
    }

}
